const domainName = getApp().globalData.domainName
const parameter = getApp().globalData.parameter

// pages/settings/settings.js
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  

  show_mall(e){

    let show_mall = e.detail.value
    wx.request({
      url: domainName + '/setShowCourseMall',
      data: {
        show_mall:JSON.stringify(show_mall)
      },...parameter,
      success: res => {
        // console.log('res',res.data)
        if(res.data.update_res){
          wx.showToast({
            title: '设置完成',
            duration: 1500,
            icon: 'success',
          })
        }
      },
    })
    
  },

  show_recruitment(e){
    let show_recruitment = e.detail.value
    wx.request({
      url: domainName + '/setShowRecruitment',
      data: {
        show_recruitment:JSON.stringify(show_recruitment)
      },...parameter,
      success: res => {
        // console.log('res',res.data)
        if(res.data.update_res){
          wx.showToast({
            title: '设置完成',
            duration: 1500,
            icon: 'success',
          })
        }
      },
    })
    
  },

  show_video(e){
    let show_video = e.detail.value
    wx.request({
      url: domainName + '/setShowVideo',
      data: {
        show_video:JSON.stringify(show_video)
      },...parameter,
      success: res => {
        // console.log('res',res.data)
        if(res.data.update_res){
          wx.showToast({
            title: '设置完成',
            duration: 1500,
            icon: 'success',
          })
        }
      },
    })
    
  },

  // 加载视频入口开关状态
  load_show_video_switch(){
    wx.request({
      url: domainName + '/show_access',
      data: {},...parameter,
      success: res => {
        this.setData({
          show_video:res.data.show_video,
          show_mall:res.data.show_mall,
          show_recruitment:res.data.show_recruitment,
        })
      },
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.load_show_video_switch()
  },

})